<?php
error_reporting ( E_ALL );
ini_set ( 'display_errors', 1 );
try {
	include_once ('class/WordXmlDocument.class.php');
	$word = new WordXmlDocument ();
	$word->setTemplateDirectory ( dirname ( __FILE__ ) . '/template/demo/' );
	$word->createElement ( 'body' );
	
	$word->body->createElement ( 'logo' );
	$word->body->addContent ( $word->body->logo );
	
	$word->body->createElement ( 'invoice_title' );
	$word->body->invoice_title->addContent ( 'This is the title' );
	$word->body->addContent ( $word->body->invoice_title );
	
	$word->body->createElement ( 'advertiser_invoice_head' );
	
	$word->body->advertiser_invoice_head->addContent ( 'Advertiser1FirstName', 'ADVERTISER' );
	$word->body->advertiser_invoice_head->addContent ( 'sz34r3aw3r', 'INVOICE_REFERENCE' );
	$word->body->advertiser_invoice_head->addContent ( "78.001,00 €", 'INVOICE_AMOUNT' );
	$word->body->advertiser_invoice_head->addContent ( 'Waiting', 'INVOICE_STATUS' );
	$word->body->advertiser_invoice_head->addContent ( '10.03.2011', 'DATE_ISSUED' );
	$word->body->advertiser_invoice_head->addContent ( '10.03.2011', 'DATE_DUE' );
	$word->body->advertiser_invoice_head->addContent ( 'Not paid', 'DATE_PAID' );
	
	$word->body->addContent ( $word->body->advertiser_invoice_head );
	
	$word->body->createElement ( 'ad_results' );
	
	for($i = 0; $i < 10; $i ++) {
		$word->body->ad_results->createElement ( 'ad_results_row' );
		$word->body->ad_results->ad_results_row->addContent ( $i, 'NR' );
		$word->body->ad_results->ad_results_row->addContent ( $i + 1, 'PUBLISHER_NAME' );
		$word->body->ad_results->ad_results_row->addContent ( $i + 2, 'PUBLISHER_CHANNEL' );
		$word->body->ad_results->ad_results_row->addContent ( $i + 3, 'COUNT' );
		$word->body->ad_results->ad_results_row->addContent ( $i + 4, 'PRICE' );
		$word->body->ad_results->ad_results_row->addContent ( $i + 5, 'TOTAL' );
		$word->body->ad_results->ad_results_row->addContent ( $i + 6, 'DETAILS' );
		$word->body->ad_results->addContent ( $word->body->ad_results->ad_results_row );
	}
	
	$word->body->addContent ( $word->body->ad_results );
	
	$word->body->createElement ( 'invoice_cost' );
	
	for($i = 0; $i < 10; $i ++) {
		$word->body->invoice_cost->createElement ( 'invoice_cost_row' );
		$word->body->invoice_cost->invoice_cost_row->addContent ( $i, 'NR' );
		$word->body->invoice_cost->invoice_cost_row->addContent ( $i + 1, 'CAMPAIGN' );
		$word->body->invoice_cost->invoice_cost_row->addContent ( $i + 2, 'DETAILS' );
		$word->body->invoice_cost->invoice_cost_row->addContent ( $i + 3, 'AMOUNT' );
		$word->body->invoice_cost->addContent ( $word->body->invoice_cost->invoice_cost_row );
	}
	
	$word->body->addContent ( $word->body->invoice_cost );
	
	echo $word->output ('test');

} catch ( Exception $e ) {
	var_dump($e);
	
	echo $e->getMessage ();
}

function write($var) {
	echo '<pre>';
	print_r ( $var );
	echo '</pre>';
}